<?php
/**
 * 总监理工程师任命书
 * @author YangL
 **/
namespace Admin\Controller;
use Common\Controller\WahahabaseController;
class CSEAppointmentLetterController extends WahahabaseController{

	public function _initialize() {
		parent::_initialize();
		$this->deal_model = D("Common/CseAppointmentLetter");
	}

	public function index(){
		/**搜索条件**/
		$where = array("d.is_deleted"=>array('neq', 1));
		$department = I('request.department');
		if($department){
			$where['construction_department'] = array('like',"%$deptname%");
		}
		$this->getDepartLevel();
		$this->indexPage($where);
		
		//总条数
//		$count=$this->deal_model->alias("c")->where($where)->count();
//		$page = $this->page($count, 20);
		
//        $cseals = $this->deal_model->alias("c")
//			->field('c.id,code,construction_department,c.appointee,supervision_engineers_no,employment_project,c.add_time,c.last_time,u.real_name')
//			->join(array(
//				' LEFT JOIN '.C('DB_PREFIX').'users u ON c.add_user = u.id',
//			))
//            ->where($where)
//            ->order("c.add_time DESC")
//            ->limit($page->firstRow, $page->listRows)
//            ->select();
//		
//		$this->assign("page", $page->show('Admin'));
//		$this->assign("cseals",$cseals);
//		
//		$this->display();
	}

	public function add(){
		$this->display();
	}
	public function add_post(){
		if(IS_POST){
			$data = array_merge($_POST, $this->saveData());
			if ($this->deal_model->create()!==false) {
				$result = $this->deal_model->add($data);
				if ($result!==false) {			
					$this->success("添加成功！", U("CSEAppointmentLetter/index"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
	
	public function edit(){
		$id = I('get.id',0,'intval');
		$result = $this->deal_model->where(array("id"=>$id))->find();
		$this->assign("result", $result);
		
		$this->display();
	}
	public function edit_post(){
		if (IS_POST) {
			$data = array_merge($_POST, $this->saveData(2));
			if ($this->deal_model->create()!==false) {
				$result=$this->deal_model->save($data);
				if ($result !== false) {
					$this->success("保存成功！", U("CSEAppointmentLetter/index"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
	public function  view(){
		 $id = I('get.id',0,'intval');
		 $data=$this->deal_model->where(array("id"=>$id))->find();
         $this->assign("result",$data);
		 $this->getDepartLevel();
         $this->display();
	}
}